var Amqp = require('./amqp');
/**
 *
 * @class
 * @extends events.EventEmitter
 * @exports Abstract as handlers.Abstract
 */
function Abstract(){
    throw new Error('Try to create instance of AbstractHandler class');
}
require('sys').inherits(Abstract, require('events').EventEmitter);
/**
 * Build amqp frame.
 *
 * @param classId
 * @param methodId
 * @param args
 * @param fields
 * @param body
 * @return
 */
Abstract.prototype.call = function(/**Number*/classId,/**Number*/methodId,/**Object*/args,/**Object*/fields,/**String*/body){
    var frame = { method: { classId: classId, methodId: methodId, arguments: args || {} } },
        A = Amqp.Class[frame.method.classId][frame.method.methodId];
    for (var i = A.enum.length - 1; i > -1; --i) {
        if (!(A.enum[i] in frame.method.arguments)) {
            frame.method.arguments[A.enum[i]] = null;
        }
    }
    if (undefined != fields) {
        frame.header = { fields: fields };
    }
    if (undefined != body) {
        frame.body = body;
    }
    this.processFrame(frame);
};
/**
 * Add additional argumetns to amqp frame and | or send frame to server.
 * This is an abstract method that should be overrided.
 *
 * @param frame
 */
Abstract.prototype.processFrame = function(/**Object*/frame){
    throw new Error('Try to call abstract Handler._processFrame() method');
};
exports.Abstract = Abstract;
